﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;

namespace CallCenter.Web.Controllers
{
    public class DateUTCController : Controller
    {
        // GET: DateUTC
        public ActionResult Index()
        {
            return View();
        }


        public class JsonUtcResult : JsonResult
        {
            private static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
            {
                DateTimeZoneHandling = DateTimeZoneHandling.Utc
            };

            public override void ExecuteResult(ControllerContext context)
            {
                if (this.JsonRequestBehavior == JsonRequestBehavior.DenyGet &&
                    string.Equals(context.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase))
                {
                    throw new InvalidOperationException("GET request not allowed");
                }

                var response = context.HttpContext.Response;

                response.ContentType = !string.IsNullOrEmpty(this.ContentType) ? this.ContentType : "application/json";

                if (this.ContentEncoding != null)
                {
                    response.ContentEncoding = this.ContentEncoding;
                }

                if (this.Data == null)
                {
                    return;
                }

                response.Write(JsonConvert.SerializeObject(this.Data, Settings));
            }
        }
    }
}